package com.tc.zigbee.zcl;
public class ZclRawCommand {
	public byte getFrameControl() {
		return frameControl;
	}
	public byte[] getManufactureCode() {
		return manufactureCode;
	}
	public byte getTransactionSnum() {
		return transactionSnum;
	}
	public byte getCommandIdentifier() {
		return commandIdentifier;
	}
	public byte[] getPayload() {
		return payload;
	}
	byte frameControl;
	byte[] manufactureCode;
	byte transactionSnum;
	byte commandIdentifier;
	byte[] payload;
	byte[] frame(){
		int length = 1 + (manufactureCode == null? 0 : 2) + 2 + (payload == null? 0 : payload.length);
		byte[] f = new byte[length];
		f[0] = frameControl;
		int ind = 1;
		if(manufactureCode != null){
			f[1] = manufactureCode[0];
			f[2] = manufactureCode[1];
			ind = 3;
		}
		f[ind++] = transactionSnum;
		f[ind++] = commandIdentifier;
		for(int i = 0 ;ind < length; ind++, i++)
			f[ind] = payload[i];
		return f;
	}
	public ZclRawCommand(byte[] data){
		int i = 0;
		frameControl = data[i++];
		byte menu = (byte)(0x04 & frameControl);
		if(menu == 4){
			manufactureCode[0] = data[i++];
			manufactureCode[1] = data[i++];
		}
		transactionSnum = data[i++];
		commandIdentifier = data[i++];
		payload = new byte[data.length - i];
		int s = i;
		for(; i < data.length; i++)
			payload[i - s] = data[i];
	}
	public ZclRawCommand() {
		// TODO Auto-generated constructor stub
	}

	
}
